using System;
using System.Collections.Generic;
using System.Text;

namespace XnaDevRu.BulletX.Utilities
{
	class SmallPool<T> where T : class, new()
	{
		public T[] Items;
		private int _index;
		public int Count;

		public void Reset( int minimumCount )
		{
			if( this.Items == null )
				this.Items = new T[ minimumCount ];
			else
			{
				if( this.Items.Length < minimumCount )
					this.Items = new T[ minimumCount ];
			}
			_index = 0;
			this.Count = 0;
		}

		public T Next()
		{
			if( _index + 1 == this.Items.Length )
				Array.Resize<T>( ref this.Items, this.Items.Length * 2 );
			T item = this.Items[ _index ];
			if( item == null )
			{
				item = new T();
				this.Items[ _index ] = item;
			}
			_index++;
			this.Count++;
			return item;
		}
	}
}
